﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Dapper.Model;
using DapperExtensions;

namespace Dapper.Extensions.Test
{
    public class SqlServerRepository:IRepository
    {
        public static SqlServerRepository _repo;

        private IDbConnection conn;

        private string ConnString = "server=47.92.31.227;database=pacs;uid=pacs;pwd=pacs;";
        public static SqlServerRepository Instance
        {
            get
            {
                if (_repo == null)
                {
                    _repo = new SqlServerRepository();
                }
                return _repo;
            }
        }



        private SqlServerRepository()
        {

        }

        public T Get<T>(object o) where T : class
        {
            using (conn = new SqlConnection(ConnString))
            {
                return conn.Get<T>(o);
            }
        }

        public int Insert<T>(T t) where T : class
        {
            using (conn = new SqlConnection(ConnString))
            {
                return conn.Insert<T>(t);
            }
        }

        public bool Update<T>(T t) where T : class
        {
            using (conn = new SqlConnection(ConnString))
            {
                return conn.Update<T>(t);
            }
        }

        public T Add<T>(T t) where T : class
        {
            using (conn = new SqlConnection(ConnString))
            {
                return conn.Delete<T>(o);
            }
        }

        public bool Delete<T>(object o) where T : class
        {
            using (conn = new SqlConnection(ConnString))
            {
                return conn.Delete<T>(o);
            }
        }

        public IEnumerable<T> GetList<T>(object o) where T : class
        {
            throw new NotImplementedException();
        }
    }
}
